<?php

namespace App\Admin\Controllers;

use App\Models\User\SystemUser;
use Encore\Admin\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class ApiController extends AdminController
{
    public function users(Request $request)
    {
        $q = $request->get('q');
        return SystemUser::where('nickname', 'like', "%$q%")->select(['uuid', 'nickname as text'])
//            ->limit(100)->get();
            ->paginate(null, ['uuid', 'nickname as text']);
    }

    public function upload(Request $request)
    {
        // key为file
        if($request->hasFile('file')) {
            $file = $request->file('file');
            $path = $file->store('images',['disk'=>'public']);
//            dd($path);
            // 返回格式
            return ['url'=> Storage::disk('public')->url($path)];
        }
    }
}
